package cn.uniqueinfo.dp.config;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @author:朱元勋
 * @mail:395910063@qq.com
 * @date:2019-01-09 20:28:26
 * @description: 防止重复 url缓存
 */
@Configuration
public class UrlCacheConfig {

    @Value("${norepeat.duration:2}")
    private Long norepeatDuration;
    @Bean
    public Cache<String,Integer> getCache(){
        // 缓存有效期单位秒
        return CacheBuilder.newBuilder().expireAfterAccess(norepeatDuration,TimeUnit.SECONDS).build();
    }
}
